<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>商品添加</title>
<link rel="stylesheet" href="../layui/css/layui.css">
<link rel="stylesheet" href="../layer/theme/default/layer.css">
<script type="text/javascript" src="../js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="../layer/layer.js"></script>
<script src="../layui/layui.all.js"></script>
<script src="../layer/mobile/layer.js"></script>
<script type="text/javascript" src="../layui/layui.js"></script>
</head>
<body>
<div style="padding:60px;">
<form id="form1" class="layui-form layui-form-pane" >
  <div class="layui-form-item">
    <label class="layui-form-label">商品名：</label>
    <div class="layui-input-inline">
      <input type="text" name="name" lay-verify="required" placeholder="商品名" autocomplete="off" class="layui-input" style="width:400px;">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">单价：</label>
    <div class="layui-input-inline">
      <input type="text" name="pri" lay-verify="required" placeholder="商品单价" autocomplete="off" class="layui-input" style="width:400px;">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">详情信息：</label>
    <div class="layui-input-inline">
      <input type="text" name="details" lay-verify="required" placeholder="详情信息" autocomplete="off" class="layui-input" style="width:400px;">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">分类：</label>
    <div class="layui-input-inline">
      <input type="text" id="ify" name="classify" lay-verify="required" placeholder="请输入昵称" autocomplete="off" class="layui-input">
    </div>
  </div>
  <!-- 上传图片 -->
  <div class="layui-input-inline">
      <input type="button" id="pic" class="layui-btn layui-btn-primary" name="pic" style="margin-left:20px;" lay-verify="required"  autocomplete="off" class="layui-input" value="上传图片">
  </div>
  <div class="layui-form-item">
    <button style="margin:15px;margin-left:40px;" type="button" id="btn1" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo2">添加商品</button>
    <button type="button" style="margin:15px;" id="btn2" class="layui-btn">返回首页</button>
  </div>
</form>

</div>
<script>
layui.config({
	  version: '1534457846312' //为了更新 js 缓存，可忽略
});
layui.use(['layer'], function(){
	var layer = layui.layer; //弹层
	$("#pic").click(function(){
		layer.open({
			type: 2,
   			area: ['320px', '280px'],
   			title:"上传图片",
    		content: 'upload.jsp' //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		})
		$("#pic").attr("color",'red');
		$("#pic").attr("font-weight",'bold');
	});
	$("#btn3").click(function(){
		$("#pic").val("上传成功!");
	});
	$("button#btn1").click(function(){

		if($("#ify").val()==null||$("#ify").val()==''||$("#ify").val()==undefined ){
			("输入有空！");
		}else{
			$.post("a.commodityadd",$("#form1").serialize(),function(data){
				var c = JSON.parse(data);
				if(c.code==0000){
					layer.msg("添加商品成功!");
					setTimeout(function(){
						location.href="commodity.html";
					}, 800);
					
				}else if(c.code==0001){
					("添加失败！图片上传失败")
				}else{
					("添加失败！");
				}
			})
		}
		
	})
	$("button#btn2").click(function(){
		location.href="commodity.html";
	})
})

</script>
</body>
</html>        
                